﻿#pragma once
#include <string>
#include <vector>

class ShouXingUtil
{
public:
	static const double PI_2;

	/// <summary>
	/// 1/3
	/// </summary>
	static const double ONE_THIRD;

	/// <summary>
	/// 1天对应的秒数
	/// </summary>
	static const int SECOND_PER_DAY;

	/// <summary>
	/// 1弧度对应的角秒
	/// </summary>
	static const double SECOND_PER_RAD;

	/// <summary>
	/// 计算气
	/// </summary>
	/// <param name="jd">儒略日</param>
	/// <returns>儒略日</returns>
	static double CalcQi(double jd);

	/// <summary>
	/// 较高精度定气计算
	/// </summary>
	/// <param name="w"></param>
	/// <returns></returns>
	static double QiHigh(double w);


	/// <summary>
	/// 已知太阳视黄经反求时间，高速低精度，最大误差不超过600秒
	/// </summary>
	/// <param name="w">太阳视黄经</param>
	/// <returns>时间</returns>
	static double SaLonT2(double w);

	/// <summary>
	/// 地球经度计算
	/// </summary>
	/// <param name="t">世纪数</param>
	/// <param name="n">取项数</param>
	/// <returns>Date分点黄经</returns>
	static double ELon(double t, int n);


	/// <summary>
	/// 已知太阳视黄经反求时间
	/// </summary>
	/// <param name="w">太阳视黄经</param>
	/// <returns>时间</returns>
	static double SaLonT(double w);

	/// <summary>
	/// 地球速度计算，误差小于万分三
	/// </summary>
	/// <param name="t">世纪数</param>
	/// <returns>地球速度</returns>
	static double Ev(double t);

	/// <summary>
	/// 太阳视黄经计算
	/// </summary>
	/// <param name="t"></param>
	/// <param name="n"></param>
	/// <returns>太阳视黄经</returns>
	static double SaLon(double t, int n);


	/// <summary>
	/// 黄经章动计算
	/// </summary>
	/// <param name="t">世纪数</param>
	/// <returns>黄经章动</returns>
	static double NutationLon2(double t);

	/// <summary>
	/// 太阳光行差计算
	/// </summary>
	/// <param name="t">世纪数</param>
	/// <returns>太阳光行差</returns>
	static double GxcSunLon(double t);


	/// <summary>
	/// 
	/// </summary>
	/// <param name="t"></param>
	/// <returns></returns>
	static double DtT(double t);


	/// <summary>
	/// 
	/// </summary>
	/// <param name="y"></param>
	/// <returns></returns>
	static double DtCalc(double y);

	/// <summary>
	/// 
	/// </summary>
	/// <param name="y"></param>
	/// <param name="jsd"></param>
	/// <returns></returns>
	static double DtExt(double y, double jsd);

	/// <summary>
	/// 低精度定朔计算，最大误差小于30分钟，平均5分
	/// </summary>
	/// <param name="w"></param>
	/// <returns></returns>
	static double QiLow(double w);


	/// <summary>
	/// 精确的气计算
	/// </summary>
	/// <param name="w">儒略日</param>
	/// <returns>儒略日</returns>
	static double QiAccurate(double w);


	/// <summary>
	/// 更精确的气计算
	/// </summary>
	/// <param name="jd">儒略日</param>
	/// <returns>儒略日</returns>
	static double QiAccurate2(double jd);

	/// <summary>
	/// 较高精度定朔计算
	/// </summary>
	/// <param name="w"></param>
	/// <returns></returns>
	static double ShuoHigh(double w);



	/// <summary>
	/// 计算朔
	/// </summary>
	/// <param name="jd">儒略日</param>
	/// <returns>儒略日</returns>
	static double CalcShuo(double jd);


	/// <summary>
	/// 已知月日视黄经差求时间
	/// </summary>
	/// <param name="w">月日视黄经差</param>
	/// <returns>时间</returns>
	static double MsaLonT(double w);

	/// <summary>
	/// 月日视黄经的差值计算
	/// </summary>
	/// <param name="t"></param>
	/// <param name="mn"></param>
	/// <param name="sn"></param>
	/// <returns></returns>
	static double MsaLon(double t, int mn, int sn);

	/// <summary>
	/// 月球速度计算
	/// </summary>
	/// <param name="t">世经数</param>
	/// <returns>月球速度</returns>
	static double Mv(double t);

	/// <summary>
	/// 低精度定朔计算，在2000至600年，误差2小时以内(仍比古代日历精准很多)
	/// </summary>
	/// <param name="w"></param>
	/// <returns></returns>
	static double ShuoLow(double w);

	/// <summary>
	/// 已知月日视黄经差求时间，高速低精度，误差不超过600秒(只验算了几千年)
	/// </summary>
	/// <param name="w">月日视黄经差</param>
	/// <returns>时间</returns>
	static double MsaLonT2(double w);


	/// <summary>
	/// 月球经度计算
	/// </summary>
	/// <param name="t">世纪数</param>
	/// <param name="n">项数比例</param>
	/// <returns>Date分点黄经</returns>
	static double MLon(double t, int n);



private:

	/// <summary>
	/// 气朔解压
	/// </summary>
	/// <param name="s">气朔压缩数据</param>
	/// <returns>解压后数据</returns>
	static std::string decode(const std::string& s);

	/// <summary>
	/// 中精度章动计算表
	/// </summary>
	static const std::vector<double> NUT_B;

	static const std::vector<double> DT_AT;

	/// <summary>
	/// 星历数据表
	/// </summary>
	static const std::vector<double> XL0;

	/// <summary>
	/// 月亮星历数据表
	/// </summary>
	static const std::vector<std::vector<double>>  XL1;

	/// <summary>
   /// 气直线拟合参数
   /// </summary>
	static const std::vector<double> QI_KB;

	/// <summary>
	/// 朔直线拟合参数
	/// </summary>
	static const std::vector<double> SHUO_KB;



	/// <summary>
	/// 气修正表
	/// </summary>
	static const std::string QB;
	/// <summary>
	/// 朔修正表
	/// </summary>
	static const std::string SB;

};

